package com.yzc.android.ui;

import android.os.Bundle;
import android.view.View;
import android.view.ViewStub;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;

import butterknife.ButterKnife;
import com.yzc.android.R;
import com.yzc.android.ui.base.activity.KDBaseActivity;

/**
 * Created by yzc on 16/4/18.
 */
public class ViewStubActivity extends KDBaseActivity {

    // this controls work perfect
    //@Bind(R.id.txtWork1)
    AutoCompleteTextView txtWork1;

    //@Bind(R.id.txtWork2)
    EditText txtWork2;

    // this controls are inside the viewstub,
    //@Bind(R.id.viewstub)
    ViewStub viewStub;

    MyDynamicView myDynamicView;

    //.... ...

    // class (inner in this example) that has stuff from your stub
    public class MyDynamicView {
        //@Bind(R.id.txtDontWork1)
        EditText txtDontWork1;

        //@Bind(R.id.txtDontWork1)
        EditText txtDontWork2;

        public MyDynamicView(View view) {
            ButterKnife.bind(this, view);
        }
    }

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setupView(final Bundle savedInstanceState) {
        View viewFromStub = viewStub.inflate();
        myDynamicView = new MyDynamicView(viewFromStub); // this is the main point where you configure your view
        Fill();
    }

    @Override
    public int getLayout() {
        return R.layout.layout_activity_first;
    }


    @Override
    public void pullToRefreshHandler() {

    }

    private void Fill() {
        txtWork1.setText("Hello 1");
        txtWork2.setText("Hello 2");

        myDynamicView.txtDontWork1.setText("Don't Work 1"); // This should work for you now
        myDynamicView.txtDontWork2.setText("Don't Work 2");
    }
}